#pragma once

#include <vector>
#include <list>
#include <memory>
#include <stdexcept>

#include "rtda/frame.h" // 引入Frame类
//#include "native/java/lang/Throwable.hpp"


namespace jvm {
namespace rtda {

class Frame; // 前向声明Frame类
//class jvm::lang::StackTraceElement;

class JvmStack {
public:
    JvmStack(size_t max_size) : _max_size(max_size), _size(0), _top(nullptr) {}
    JvmStack(const JvmStack&) = delete; // 禁止拷贝构造
    JvmStack& operator=(const JvmStack&) = delete; // 禁止赋值操作
    JvmStack(JvmStack&&) = default; // 允许移动构造
    JvmStack& operator=(JvmStack&&) = default; // 允许移动赋值
    ~JvmStack() = default;

    void push(std::shared_ptr<Frame> frame);

    std::shared_ptr<Frame> pop();

    std::shared_ptr<Frame> top() const;

    bool empty() const;

    void clear();
    size_t size() const;

    // 0 是_top的位置
    std::shared_ptr<Frame> getFrameUnderTop(uint32_t dpos) const;

    std::list<std::shared_ptr<Frame>> getFrames();

    //std::vector<std::shared_ptr<lang::StackTraceElement>> getStackTraceInfo() const;

private:
    //std::shared_ptr<lang::StackTraceElement> createStackTraceElement(const std::shared_ptr<rtda::Frame> pFrame) const;

private:
    const size_t _max_size;
    size_t _size;
    std::shared_ptr<Frame> _top;
    std::list<std::shared_ptr<Frame>> _frames;
};

} // namespace rtda
} // namespace jvm
